<?php
defined('IN_IXDCW') or exit('Access Denied');
$do = new StoreModule($moduleid);
$menus = array (
    array($MOD['name'].'列表', '?moduleid='.$moduleid),
    array('审核'.$MOD['name'], '?moduleid='.$moduleid.'&action=check'),
    array('未通过'.$MOD['name'], '?moduleid='.$moduleid.'&action=reject'),
);

if($_catids) require DT_ROOT.'/admin/admin_check.inc.php';

if(in_array($action, array('', 'check', 'reject', 'recycle'))) {
	$sfields = array('公司名',);
	$dfields = array('company');
	$sorder  = array('结果排序方式', '添加时间降序', '添加时间升序', '更新时间降序', '更新时间升序', );
	$dorder  = array($MOD['order'], 'addtime DESC', 'addtime ASC', 'edittime DESC', 'edittime ASC');

	isset($fields) && isset($dfields[$fields]) or $fields = 0;
	isset($order) && isset($dorder[$order]) or $order = 0;

	isset($datetype) && in_array($datetype, array('edittime', 'addtime')) or $datetype = 'addtime';
	$fromdate = isset($fromdate) && preg_match("/^([0-9]{8})$/", $fromdate) ? $fromdate : '';
	$fromtime = $fromdate ? strtotime($fromdate.' 0:0:0') : 0;
	$todate = isset($todate) && preg_match("/^([0-9]{8})$/", $todate) ? $todate : '';
	$totime = $todate ? strtotime($todate.' 23:59:59') : 0;

	$thumb = isset($thumb) ? intval($thumb) : 0;
	$link = isset($link) ? intval($link) : 0;
	$guest = isset($guest) ? intval($guest) : 0;
	$itemid or $itemid = '';

	$fields_select = dselect($sfields, 'fields', '', $fields);
	$order_select  = dselect($sorder, 'order', '', $order);
	$condition = '';
	if($keyword) $condition .= " AND $dfields[$fields] LIKE '%$keyword%'";
	if($fromtime) $condition .= " AND `$datetype`>=$fromtime";
	if($totime) $condition .= " AND `$datetype`<=$totime";
	if($psize) $do->setPagesize($psize);
	if($itemid) $condition = " AND itemid=$itemid";

	$timetype = strpos($dorder[$order], 'edit') === false ? 'add' : '';
}
switch($action) {
	case 'edit':
		$uid or msg('请选择'.$MOD['name']);
		$do->setUserid($uid);
		if($submit) {
			$db->query(Sql::update($do->getTable(), 'status='.$status, "userid={$uid}"));
			dmsg('修改成功', $forward);
		} else {
			$item = $do->getOne();
			extract($item);
			$arbid = explode(',', $arbid);
			$BRANDS = AutoBrand::getBrands();
			$selectedBrands = array();
			foreach($arbid as $t) {
				if (isset($BRANDS[$t])) {
					$selectedBrands[$t] = $BRANDS[$t];
				}
			}
			$cates = $catid ? explode(',', $catid) : array();
			$addtime = timetodate($addtime);
			include tpl($action, $module);
		}
	break;
	case 'delete':
		$uid or msg('请选择'.$MOD['name']);

		isset($recycle) ? $do->recycle($uid) : $do->delete($uid);
		dmsg('删除成功', $forward);
	break;
	case 'reject':
		if($uid && !$psize) {
			$do->reject($uid);
			dmsg('拒绝成功', $forward);
		} else {
			$lists = $do->getList('status=1'.$condition, $dorder[$order]);
			$menuid = 2;
			include tpl('index', $module);
		}
	break;
	case 'check':
		if($uid && !$psize) {
			$do->check($uid);
			dmsg('审核成功', $forward);
		} else {
			$lists = $do->getList('status=2'.$condition, $dorder[$order]);
			$menuid = 1;
			include tpl('index', $module);
		}
	break;
	default:
		$lists = $do->getList('status=3'.$condition, $dorder[$order]);
		$menuid = 0;
		include tpl('index', $module);
	break;
}
?>